/*
 * Copyright (c) 2011, Gerold Roth
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 * * Neither the name of the gradecalculator.net nor the
 *   names of its contributors may be used to endorse or promote products
 *   derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 */
package netgradecalculator.plugin.importer.hsrw.lsf.pdf;

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import net.gradecalculator.plugin.importer.data.ImportedExaminationResult;
import net.gradecalculator.plugin.importer.interfaces.IFileImportPlugin;
import netgradecalculator.plugin.importer.hsrw.lsf.pdf.util.PDFUtil;

public class LsfPdfImportPlugin implements IFileImportPlugin
{
	private final String name = "LSF-PDF-Importer";
	private final String version = "0.9";
	private final String statusLineText = "Importiert durch das LSF erzeugte Notenspiegel";
	
	private LsfPdfParser data = null;
	
	private void validate()
	{
		if (data == null) {
			throw new IllegalStateException("Please start import first");
		}
	}

	@Override
	public String getName() 
	{
		return name;
	}

	@Override
	public String getVersion() 
	{
		return version;
	}

	@Override
	public String getStatusLineText() 
	{
		return statusLineText;
	}

	@Override
	public List<ImportedExaminationResult> getResults() 
	{
		validate();
		return data.getResults();
	}

	@Override
	public String getUniversity() 
	{
		validate();
		return data.getUniversityName();
	}

	@Override
	public String getDegree() 
	{
		validate();
		return data.getDegree();
	}

	@Override
	public String getCourseOfScience() 
	{
		validate();
		return data.getCourseOfStudies();
	}

	@Override
	public String getSemester() 
	{
		validate();
		return data.getLowestSemester();
	}

	@Override
	public String getStudent() 
	{
		validate();
		return data.getStudentName();
	}
	
	@Override
	public List<String> getSelectedModuleLists() 
	{	
		return new LinkedList<String>();
	}

	@Override
	public List<String> getExtensions() 
	{
		final List<String> result = new ArrayList<String>();
		result.add("pdf");
		return result;
	}

	@Override
	public void startImport(final String fileName) 
	{
		try {
			final String fileContent = PDFUtil.readFile(fileName);
			data = new LsfPdfParser(fileContent);
		} catch (final IOException e) {
			throw new IllegalStateException("Exception at starting import.", e);
		}
	}
	
}

